function ready() {
    var opAction='';
	// var cityGrid = function() {
	var conditionStore = new Ext.data.Store({
				url : 'City!queryCity.action',
				reader : new Ext.data.JsonReader({
							root : 'result.result',
							  id: 'conditionStore',
							totalProperty : 'result.totalCount'
						}, [{
								name : 'city_id',
									mapping : 'city_id'
								},{
								name : 'city_name',
									mapping : 'city_name'
								}, {
									name : 'city_code',
									mapping : 'city_code'
								}, {
									name : 'city_pinyin',
									mapping : 'city_pinyin'
								}, {
									name : 'city_abbr_pinyin',
									mapping : 'city_abbr_pinyin'
								}])
			});
	var cm = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		new Ext.grid.CheckboxSelectionModel(),
		{
			    header : '',
				hidden:true,
				dataIndex : 'city_id',
				width : 130
		
			},{
				header : '市编码',
				dataIndex : 'city_code',
				width : 130
		
			}, {
				header : '城市名',
				dataIndex : 'city_name',
				width : 70
		
			}, {
				header : '城市全拼',
				dataIndex : 'city_pinyin',
				width : 70
				
			}, {
				header : '城市简拼',
				dataIndex : 'city_abbr_pinyin',
				width : 70
			}]);

	// create the editor grid

var newWin = getAddWindow();
var modifyWin = getModifyWindow();
conditionStore.reload();
	var addAction = new Ext.Action({
				text : '新增市',
				handler : function() {
					newWin.show();
					opAction='add';
				}
			});
	var editAction = new Ext.Action({
		text : '修改市',
		// iconCls:'all',
		handler : function() {
			var length = grid.getSelectionModel().getSelections().length
			if (length < 1) {
				Ext.Msg.alert('警告', '请选择需要修改的城市');
				return;
			}
			if (length > 1) {
				Ext.Msg.alert('警告', '只能选择一个城市进行修改');
				return;
			}
			Ext.Ajax.request({
				url : "City!queryCityDetails.action?city_id="
						+ grid.getSelectionModel().getSelections()[0]
								.get('city_id'),
				method : "post",
				success : function(response, options) {
					var responseTextVale = Ext.util.JSON.decode(response.responseText);
					record = responseTextVale.resultL[0];
					modifyWin.findById('PROVINCE_ID2').setValue(record.province_id);
					modifyWin.findById('PROVINCE_NAME2').setValue(record.province_name);
					modifyWin.findById('CITY_ID2').setValue(record.city_id);
					modifyWin.findById('CITY_NAME2').setValue(record.city_name);
					modifyWin.findById('CITY_CODE2').setValue(record.city_code);
					modifyWin.findById('CITY_PINYIN2').setValue(record.city_pinyin);
					modifyWin.findById('CITY_ABBR_PINYIN2').setValue(record.city_abbr_pinyin);
				}
			});
			opAction = 'modify';
			modifyWin.show();

		}
	});
		var delAction = new Ext.Action({
		text:'删除市',
		handler:function(){
			var length = grid.getSelectionModel().getSelections().length
			if (length < 1) {
				Ext.Msg.alert('警告', '请选择需要删除的城市');
				return;
			}
			Ext.MessageBox.show({
				title : '提示',
				msg : '您选中了' + length + '条记录进行删除,请问您确认吗?',
				buttons : Ext.MessageBox.OKCANCEL,
				fn : function(btn) {
					if (btn == "ok") {

						var deleteCityId = [];
							var rs = grid.getSelectionModel().getSelections();
							for (var i = 0;i < length; i++) {
								var cityId = rs[i].data.city_id;
								deleteCityId.push(cityId);
								 
							}
							
						Ext.Ajax.request({
							url : "City!delCity.action?city_id="
									+ Ext.encode(deleteCityId),
							method : "post",
							success : function(response, options) {
								conditionStore.reload();
								Ext.Msg.alert('提示', '删除操作成功！');
							}
						});

					}
					if (btn == "cancel") {
						return;
					}
				}
			});
	 

			
		}
		});
	// store.reload();
	// grid.render(Ext.getBody());

	var conditionForm = new Ext.form.FormPanel({
				// labelAlign: 'top',
				frame : true,
				title : '查询条件',
				id : 'conditionForm',
				bodyStyle : 'padding:5px 5px 0',
				//url : 'Tax!saveTax.action',
				
				items : [{
					layout : 'column',
					columnWidth:1,
					items : [{
								columnWidth : 0.5,
								layout : 'form',
								items : [{
											xtype : 'textfield',
											fieldLabel : '城市名称',
											name : 'CITY_NAME',
											id : 'CITY_NAME',
											anchor : '95%',
											blankText : '名称不能为空',
											emptyText : ''
										}]
							}, {
								columnWidth : 0.5,
								layout : 'form',
								items : [{
											xtype : 'textfield',
											fieldLabel : '城市编码',
											name : 'CITY_CODE',
											id : 'CITY_CODE',
											anchor : '95%',
											emptyText : '',
											blankText : '城市编码不能为空'
										}]
							}, {
								columnWidth : 0.5,
								layout : 'form',
								items : [{
									xtype : 'button',
									text : '查询',
									handler : function() {
										conditionStore.on('beforeload', function() {
													conditionStore.baseParams = {
														CITY_CODE : Ext.getCmp('CITY_CODE').getValue(),
														CITY_NAME : Ext.getCmp('CITY_NAME').getValue()
													}
												});
										conditionStore.reload();
									}
								}]
							}]
				}]
			});

 function getAddWindow() {
			    var provinceStore = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : 'Province!queryProvinceList.action'
						}),
				reader : new Ext.data.JsonReader({
							root : 'resultL',
							id : 'id'
						}, [{
									name : 'province_id',
									mapping : 'province_id'
								}, {
									name : 'province_name',
									mapping : 'province_name'
								}])
			}); 
			
	var addPanel = new Ext.form.FormPanel({
				frame : true,
				id : 'addPanelForm',
				bodyStyle : 'padding:5px 5px 0',
				items : [{
							layout : 'column',
							
							items : [{
										columnWidth : 1,
										layout : 'form',
										items : [{
													xtype : 'hidden',
													name : 'CITY_ID1',
													id : 'CITY_ID1'
												}]
									}, {
										columnWidth : .5,
										layout : 'form',
										items : [{
													xtype : 'combo',
													store:provinceStore,
													valueField :"province_id",   
           											displayField: "province_name",   
													fieldLabel : '省份名称',
													name : 'PROVINCE_NAME1',
													id : 'PROVINCE_NAME1',
													anchor : '100%',
													allowBlank : false,
													blankText : '省份名称不能为空',
													emptyText : '请选择省份名称',
													triggerAction: 'all',
													editable: false
										 
												},{
													xtype : 'textfield',
													fieldLabel : '城市编码',
													name : 'CITY_CODE1',
													id : 'CITY_CODE1',
													allowBlank : false,
													anchor : '100%',
													emptyText : '请输入城市编码',
													blankText : '城市编码不能为空'
												} , {
													xtype : 'textfield',
													fieldLabel : '城市全拼',
													name : 'CITY_PINYIN1',
													id : 'CITY_PINYIN1',
													anchor : '100%'

												}]
									}, {
										columnWidth : .5,
										layout : 'form',
										items : [{
													xtype : 'textfield',
													fieldLabel : '城市名称',
													name : 'CITY_NAME1',
													id : 'CITY_NAME1',
													anchor : '100%',
													allowBlank : false,
													blankText : '名称不能为空',
													emptyText : '请输入城市名称'
												}, {
													xtype : 'textfield',
													fieldLabel : '城市简拼',
													name : 'CITY_ABBR_PINYIN1',
													id : 'CITY_ABBR_PINYIN1',
													anchor : '100%',
													allowBlank : true,
													emptyText : ''
												}]
									}]
						}]
			});
//新增市的窗口
	var addWin = new Ext.Window({
		buttonalign : 'right',
		closable : true,
		draggable : true,
		height : 170,
		top : 10,
		region : 'center',
		plain : true,
		items : [addPanel],
		title : '新增城市信息',
		width : 550,
		listeners : {
			"beforedestroy" : function(obj) {
				return false;
			},
			"beforeshow" : function(obj) {
				deletedJson = [];
				addPanel.getForm().reset();
				return true;
			},
			"beforehide" : function(obj) {
				addPanel.getForm().reset();
				return true;
			}
		},
		buttons : [{
			text : '保存并继续新增',
			id : 'continue',
			handler : function() {
				 if (!addPanel.findById('PROVINCE_NAME1').validate()) {
						Ext.Msg.alert('','省份名称必填');
						addPanel.findById("PROVINCE_NAME1").focus();
						return;
					}
					 if (!addPanel.findById('CITY_NAME1').validate()) {
						Ext.Msg.alert('','城市名称必填');
						addPanel.findById("CITY_NAME1").focus();
						return;
					}
				
				 if (!addPanel.findById('CITY_CODE1').validate()) {
						Ext.Msg.alert('','城市编号必填');
						addPanel.findById("CITY_CODE1").focus();
						return;
					}				 
				Ext.Ajax.request({
					url : 'City!updateCity.action',
					method : 'post',
					params : {
						city : "{\"city\":{"
								+ "\"city_id\":\""
								+ addPanel.findById("CITY_ID1").getValue()
							   + "\",\"province_id\":\""
								+ addPanel.findById("PROVINCE_NAME1").getValue()
								+ "\",\"city_name\":\""
								+ addPanel.findById("CITY_NAME1").getValue()
								+ "\",\"city_code\":\""
								+ addPanel.findById("CITY_CODE1").getValue()
								+ "\",\"city_pinyin\":\""
								+ addPanel.findById("CITY_PINYIN1").getValue()
								+ "\",\"city_abbr_pinyin\":\""
								+ addPanel.findById("CITY_ABBR_PINYIN1").getValue()
								+ "\"}}"
					},
					success : function() {
						conditionStore.commitChanges();
						conditionStore.on('beforeload', function() {
									conditionStore.baseParams = {}
								});
						
									Ext.MessageBox.show({
									title:'提示',
									msg:'新增操作成功！',
									buttons:Ext.MessageBox.OK,
									fn:function(btn) {
										if (btn == "ok"){
										 
									newWin.findById('CITY_ID1').setValue('');
									newWin.findById('CITY_NAME1').setValue('');
									newWin.findById('CITY_CODE1').setValue('');
									newWin.findById('CITY_PINYIN1').setValue('');
						 			newWin.findById('CITY_ABBR_PINYIN1').setValue('');
										}
									}
								});	
						//addWin.hide();
								conditionStore.reload();
					},
					failure : function() {
						Ext.Msg.alert('警告', '由于异常原因，提交数据失败！');
					}
				});
			}
		},{
			text : '新增',
			id : 'save',
			handler : function() {
			 
				 if (!addPanel.findById('PROVINCE_NAME1').validate()) {
						Ext.Msg.alert('','省份名称必填');
						addPanel.findById("PROVINCE_NAME1").focus();
						return;
					}
					 if (!addPanel.findById('CITY_NAME1').validate()) {
						Ext.Msg.alert('','城市名称必填');
						addPanel.findById("CITY_NAME1").focus();
						return;
					}
				
				 if (!addPanel.findById('CITY_CODE1').validate()) {
						Ext.Msg.alert('','城市编号必填');
						addPanel.findById("CITY_CODE1").focus();
						return;
					}
					
				
				Ext.Ajax.request({
					url : 'City!updateCity.action',
					method : 'post',
					params : {
						city : "{\"city\":{"
								+ "\"city_id\":\""
								+ addPanel.findById("CITY_ID1").getValue()
								+ "\",\"province_id\":\""
								+ addPanel.findById("PROVINCE_NAME1").getValue()
								+ "\",\"city_name\":\""
								+ addPanel.findById("CITY_NAME1").getValue()
								+ "\",\"city_code\":\""
								+ addPanel.findById("CITY_CODE1").getValue()
								+ "\",\"city_pinyin\":\""
								+ addPanel.findById("CITY_PINYIN1").getValue()
								+ "\",\"city_abbr_pinyin\":\""
								+ addPanel.findById("CITY_ABBR_PINYIN1").getValue()
								+ "\"}}"
					},
					success : function() {
						conditionStore.commitChanges();
						conditionStore.on('beforeload', function() {
									conditionStore.baseParams = {}
								});
						
									Ext.MessageBox.show({
									title:'提示',
									msg:'新增操作成功！',
									buttons:Ext.MessageBox.OK,
									fn:function(btn) {
										if (btn == "ok"){
										addWin.hide();
										}
									}
								});	
						addWin.hide();
						conditionStore.reload();
					},
					failure : function() {
						Ext.Msg.alert('警告', '由于异常原因，提交数据失败！');
					}
				});

			}
		}, {
			text : '取消',
			id : 'cancel',
			handler : function() {
					newWin.hide();
			}
		}]
	});
	return addWin;
}




//修改窗口
 function getModifyWindow() {
 	    var provinceStore = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : 'Province!queryProvinceList.action'
						}),
				reader : new Ext.data.JsonReader({
							root : 'resultL',
							id : 'id'
						}, [{
									name : 'province_id',
									mapping : 'province_id'
								}, {
									name : 'province_name',
									mapping : 'province_name'
								}])
			}); 
	var addPanel = new Ext.form.FormPanel({
				frame : true,
				id : 'modifyPanelForm',
				bodyStyle : 'padding:5px 5px 0',
				items : [{
							layout : 'column',
							items : [{
										columnWidth : 1,
										layout : 'form',
										items : [{
													xtype : 'hidden',
													name : 'CITY_ID2',
													id : 'CITY_ID2'
												},{
													xtype : 'hidden',
													name : 'PROVINCE_ID2',
													id : 'PROVINCE_ID2'
												}]
									}, {
										columnWidth : .5,
										layout : 'form',
										items : [{
													xtype : 'combo',
													store:provinceStore,
													valueField :"province_id",   
           											displayField: "province_name",   
													fieldLabel : '省份名称',
													name : 'PROVINCE_NAME2',
													id : 'PROVINCE_NAME2',
													anchor : '95%',
													allowBlank : false,
													blankText : '名称不能为空',
													emptyText : '',
													triggerAction: 'all',
													editable: false,
													listeners : {
											select : {
												fn : function(combox) {
													addPanel
															.findById("PROVINCE_ID2")
															.setValue(combox.value);
												}
											}
										}
										 
												},{
													xtype : 'textfield',
													fieldLabel : '城市名称',
													name : 'CITY_NAME2',
													id : 'CITY_NAME2',
													anchor : '95%',
													allowBlank : false,
													blankText : '名称不能为空',
													emptyText : ''
												}, {
													xtype : 'textfield',
													fieldLabel : '城市全拼',
													name : 'CITY_PINYIN2',
													id : 'CITY_PINYIN2',
													anchor : '95%'

												}]
									}, {
										columnWidth : .5,
										layout : 'form',
										items : [{
													xtype : 'textfield',
													fieldLabel : '城市编码',
													name : 'CITY_CODE2',
													id : 'CITY_CODE2',
													anchor : '95%',
													emptyText : '',
													blankText : '城市编码不能为空'
												}, {
													xtype : 'textfield',
													fieldLabel : '城市简拼',
													name : 'CITY_ABBR_PINYIN2',
													id : 'CITY_ABBR_PINYIN2',
													anchor : '95%',
													allowBlank : true,
													emptyText : ''
												}]
									}]
						}]
			});
			
//修改市的窗口
	var addWin = new Ext.Window({
		buttonalign : 'right',
		closable : true,
		draggable : true,
		height : 170,
		top : 10,
		region : 'center',
		plain : true,
		items : [addPanel],
		title : '城市信息',
		width : 550,
		listeners : {
			"beforedestroy" : function(obj) {
				return false;
			},
			"beforeshow" : function(obj) {
				deletedJson = [];
				return true;
			},
			"beforehide" : function(obj) {
				return true;
			}
		},
		buttons : [{
			text : '修改',
			id : 'save',
			handler : function() {
		 
				Ext.Ajax.request({
					url : 'City!updateCity.action',
					method : 'post',
					params : {
						city : "{\"city\":{"
								+ "\"city_id\":\""
								+ addPanel.findById("CITY_ID2").getValue()
					   			+ "\",\"province_id\":\""
								+ addPanel.findById("PROVINCE_ID2").getValue()
								+ "\",\"city_name\":\""
								+ addPanel.findById("CITY_NAME2").getValue()
								+ "\",\"city_code\":\""
								+ addPanel.findById("CITY_CODE2").getValue()
								+ "\",\"city_pinyin\":\""
								+ addPanel.findById("CITY_PINYIN2").getValue()
								+ "\",\"city_abbr_pinyin\":\""
								+ addPanel.findById("CITY_ABBR_PINYIN2").getValue()
								+ "\"}}"
					},
					success : function() {
						conditionStore.commitChanges();
						conditionStore.on('beforeload', function() {
									conditionStore.baseParams = {}
								});
						
									Ext.MessageBox.show({
									title:'提示',
									msg:'修改成功！',
									buttons:Ext.MessageBox.OK,
									fn:function(btn) {
										if (btn == "ok"){
										addWin.hide();
										}
									}
								});	
						addWin.hide();
					},
					failure : function() {
						Ext.Msg.alert('警告', '由于异常原因，提交数据失败！');
					}
				});

			}
		}, {
			text : '取消',
			id : 'cancel',
			handler : function() {
					modifyWin.hide();
			 
			}
		}]
	});
	return addWin;
}
	conditionForm.render(Ext.getBody());
	var grid = new Ext.grid.GridPanel({
				id : "cityGrid",
				cm : cm,
				sm:new Ext.grid.CheckboxSelectionModel(),
				store : conditionStore,
				height : document.body.clientHeight
						- Ext.getCmp('conditionForm').getInnerHeight()
						- Ext.getCmp('conditionForm').getFrameHeight(),
				loadMask : true,
				loadMask : {
					msg : '正在加载数据...'
				},
				frame : true,
				clicksToEdit : 1,
				tbar : [addAction, '-', editAction, '-',delAction],
				bbar:new Ext.PagingToolbar({
			pageSize:pageSize,
			store:conditionStore,
			displayInfo:true,
			dispalyMsg:'显示第{0}条到{1}条记录，一共{2}条',
			emptyMsg:'没有记录'
		})
	});
	grid.render(Ext.getBody());




}
// //////////////////

